package com.ruoyi.project.mesworkshop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.project.system.domain.SysDictType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.common.zx.PageData;
import com.ruoyi.project.mesworkshop.service.impl.MesWorkshopServiceImpl;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 车间Controller
 *
 * @author zx
 * @date 2023-06-06
 */
@RestController
@RequestMapping("/mes/workshop/mesworkshop")
public class MesWorkshopController extends BaseController {
    @Autowired
    private MesWorkshopServiceImpl mesWorkshopService;

    /**
     * 查询车间列表
     */
    @PreAuthorize("@ss.hasPermi('mes/workshop:mesworkshop:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = mesWorkshopService.selectMesWorkshopList(pd);
        return getDataTable(list);
    }

    /**
     * 导出车间列表
     */
    @PreAuthorize("@ss.hasPermi('mes/workshop:mesworkshop:export')")
    @Log(title = "车间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageData pd) {
        List<PageData> list = mesWorkshopService.selectMesWorkshopList(pd);
        ExcelUtil<PageData> util = new ExcelUtil<PageData>(PageData. class);
        util.exportExcel(response, list, "车间数据");
    }

    /**
     * 获取车间详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes/workshop:mesworkshop:query')")
    @GetMapping(value = "/{workshop_code}")
    public AjaxResult getInfo(@PathVariable("workshop_code") String workshop_code) {
        return success(mesWorkshopService.selectMesWorkshopByWorkshop_code(workshop_code));
    }

    /**
     * 新增车间
     */
    @PreAuthorize("@ss.hasPermi('mes/workshop:mesworkshop:add')")
    @Log(title = "车间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PageData pd) {
        return toAjax(mesWorkshopService.insertMesWorkshop(pd));
    }

    /**
     * 修改车间
     */
    @PreAuthorize("@ss.hasPermi('mes/workshop:mesworkshop:edit')")
    @Log(title = "车间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PageData pd) {
        return toAjax(mesWorkshopService.updateMesWorkshop(pd));
    }

    /**
     * 删除车间
     */
    @PreAuthorize("@ss.hasPermi('mes/workshop:mesworkshop:remove')")
    @Log(title = "车间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{workshop_codes}")
    public AjaxResult remove(@PathVariable String[] workshop_codes) {
        return toAjax(mesWorkshopService.deleteMesWorkshopByWorkshop_codes(workshop_codes));
    }

    /**
     * 获取车间选择框列表
     */

    @GetMapping("/optionselect")
    public AjaxResult optionselect() {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> mesWorkshop = mesWorkshopService.selectMesWorkshopType(pd);
        return success(mesWorkshop);
    }

//    @GetMapping("/dictSelect")
//    public AjaxResult dictSelect() {
//        startPage();
//        PageData pd = this.getPageData();
//        List<PageData> list = mesWorkshopService.dictSelect(pd);
//        long total = new PageInfo(list).getTotal();
//        return AjaxResult.success(list,total);
//    }
}
